home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / mfbfillsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  30.7 KB  |  1,058 lines

  1. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /* $XConsortium: mfbfillsp.c,v 5.6 89/11/24 18:02:25 rws Exp $ */
  26. #include "X.h"
  27. #include "Xmd.h"
  28. #include "gcstruct.h"
  29. #include "window.h"
  30. #include "pixmapstr.h"
  31. #include "scrnintstr.h"
  32. #include "windowstr.h"
  33. #include "mfb.h"
  34. #include "maskbits.h"
  35.  
  36. #include "servermd.h"
  37.  
  38. /* scanline filling for monochrome frame buffer
  39.    written by drewry, oct 1986
  40.  
  41.    these routines all clip.  they assume that anything that has called
  42. them has already translated the points (i.e. pGC->miTranslate is
  43. non-zero, which is howit gets set in mfbCreateGC().)
  44.  
  45.    the number of new scnalines created by clipping ==
  46. MaxRectsPerBand * nSpans.
  47.  
  48.     FillSolid is overloaded to be used for OpaqueStipple as well,
  49. if fgPixel == bgPixel.  
  50.  
  51.  
  52.     FillTiled is overloaded to be used for OpaqueStipple, if
  53. fgPixel != bgPixel.  based on the fill style, it uses
  54. {RotatedPixmap, gc.alu} or {RotatedPixmap, PrivGC.ropOpStip}
  55. */
  56.  
  57.  
  58. void mfbBlackSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  59.     DrawablePtr pDrawable;
  60.     GCPtr    pGC;
  61.     int        nInit;            /* number of spans to fill */
  62.     DDXPointPtr pptInit;        /* pointer to list of start points */
  63.     int        *pwidthInit;        /* pointer to list of n widths */
  64.     int     fSorted;
  65. {
  66.                 /* next three parameters are post-clip */
  67.     int n;            /* number of spans to fill */
  68.     register DDXPointPtr ppt;    /* pointer to list of start points */
  69.     register int *pwidth;    /* pointer to list of n widths */
  70.     int *addrlBase;        /* pointer to start of bitmap */
  71.     int nlwidth;        /* width in longwords of bitmap */
  72.     register int *addrl;    /* pointer to current longword in bitmap */
  73.     register int nlmiddle;
  74.     register int startmask;
  75.     register int endmask;
  76.     int *pwidthFree;        /* copies of the pointers to free */
  77.     DDXPointPtr pptFree;
  78.  
  79.     if (!(pGC->planemask & 1))
  80.     return;
  81.  
  82.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  83.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  84.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  85.     if(!pptFree || !pwidthFree)
  86.     {
  87.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  88.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  89.     return;
  90.     }
  91.     pwidth = pwidthFree;
  92.     ppt = pptFree;
  93.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  94.             pptInit, pwidthInit, nInit,
  95.             ppt, pwidth, fSorted);
  96.  
  97.     if (pDrawable->type == DRAWABLE_WINDOW)
  98.     {
  99.     addrlBase = (int *)
  100.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  101.     nlwidth = (int)
  102.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  103.     }
  104.     else
  105.     {
  106.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  107.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  108.     }
  109.  
  110.     while (n--)
  111.     {
  112.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  113.  
  114.     if (*pwidth)
  115.     {
  116.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  117.         {
  118.         /* all bits inside same longword */
  119.         maskpartialbits(ppt->x, *pwidth, startmask);
  120.             *addrl &= ~startmask;
  121.         }
  122.         else
  123.         {
  124.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  125.         if (startmask)
  126.             *addrl++ &= ~startmask;
  127.         Duff (nlmiddle, *addrl++ = 0x0);
  128.         if (endmask)
  129.             *addrl &= ~endmask;
  130.         }
  131.     }
  132.     pwidth++;
  133.     ppt++;
  134.     }
  135.     DEALLOCATE_LOCAL(pptFree);
  136.     DEALLOCATE_LOCAL(pwidthFree);
  137. }
  138.  
  139.  
  140.  
  141. void mfbWhiteSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  142.     DrawablePtr pDrawable;
  143.     GCPtr    pGC;
  144.     int        nInit;            /* number of spans to fill */
  145.     DDXPointPtr pptInit;        /* pointer to list of start points */
  146.     int        *pwidthInit;        /* pointer to list of n widths */
  147.     int     fSorted;
  148. {
  149.                 /* next three parameters are post-clip */
  150.     int n;            /* number of spans to fill */
  151.     register DDXPointPtr ppt;    /* pointer to list of start points */
  152.     register int *pwidth;    /* pointer to list of n widths */
  153.     int *addrlBase;        /* pointer to start of bitmap */
  154.     int nlwidth;        /* width in longwords of bitmap */
  155.     register int *addrl;    /* pointer to current longword in bitmap */
  156.     register int nlmiddle;
  157.     register int startmask;
  158.     register int endmask;
  159.     int *pwidthFree;        /* copies of the pointers to free */
  160.     DDXPointPtr pptFree;
  161.  
  162.     if (!(pGC->planemask & 1))
  163.     return;
  164.  
  165.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  166.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  167.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  168.     if(!pptFree || !pwidthFree)
  169.     {
  170.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  171.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  172.     return;
  173.     }
  174.     pwidth = pwidthFree;
  175.     ppt = pptFree;
  176.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  177.             pptInit, pwidthInit, nInit,
  178.             ppt, pwidth, fSorted);
  179.  
  180.     if (pDrawable->type == DRAWABLE_WINDOW)
  181.     {
  182.     addrlBase = (int *)
  183.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  184.     nlwidth = (int)
  185.          (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  186.     }
  187.     else
  188.     {
  189.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  190.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  191.     }
  192.  
  193.     while (n--)
  194.     {
  195.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  196.  
  197.     if (*pwidth)
  198.     {
  199.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  200.         {
  201.         /* all bits inside same longword */
  202.         maskpartialbits(ppt->x, *pwidth, startmask);
  203.         *addrl |= startmask;
  204.         }
  205.         else
  206.         {
  207.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  208.         if (startmask)
  209.             *addrl++ |= startmask;
  210.         Duff (nlmiddle, *addrl++ = 0xffffffff);
  211.         if (endmask)
  212.             *addrl |= endmask;
  213.         }
  214.     }
  215.     pwidth++;
  216.     ppt++;
  217.     }
  218.     DEALLOCATE_LOCAL(pptFree);
  219.     DEALLOCATE_LOCAL(pwidthFree);
  220. }
  221.  
  222.  
  223.  
  224. void mfbInvertSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  225.     DrawablePtr pDrawable;
  226.     GCPtr    pGC;
  227.     int        nInit;            /* number of spans to fill */
  228.     DDXPointPtr pptInit;        /* pointer to list of start points */
  229.     int        *pwidthInit;        /* pointer to list of n widths */
  230.     int     fSorted;
  231. {
  232.                 /* next three parameters are post-clip */
  233.     int n;            /* number of spans to fill */
  234.     register DDXPointPtr ppt;    /* pointer to list of start points */
  235.     register int *pwidth;    /* pointer to list of n widths */
  236.     int *addrlBase;        /* pointer to start of bitmap */
  237.     int nlwidth;        /* width in longwords of bitmap */
  238.     register int *addrl;    /* pointer to current longword in bitmap */
  239.     register int nlmiddle;
  240.     register int startmask;
  241.     register int endmask;
  242.     int *pwidthFree;        /* copies of the pointers to free */
  243.     DDXPointPtr pptFree;
  244.  
  245.     if (!(pGC->planemask & 1))
  246.     return;
  247.  
  248.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  249.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  250.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  251.     if(!pptFree || !pwidthFree)
  252.     {
  253.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  254.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  255.     return;
  256.     }
  257.     pwidth = pwidthFree;
  258.     ppt = pptFree;
  259.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  260.             pptInit, pwidthInit, nInit,
  261.             ppt, pwidth, fSorted);
  262.  
  263.     if (pDrawable->type == DRAWABLE_WINDOW)
  264.     {
  265.     addrlBase = (int *)
  266.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  267.     nlwidth = (int)
  268.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  269.     }
  270.     else
  271.     {
  272.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  273.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  274.     }
  275.  
  276.     while (n--)
  277.     {
  278.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  279.  
  280.     if (*pwidth)
  281.     {
  282.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  283.         {
  284.         /* all bits inside same longword */
  285.         maskpartialbits(ppt->x, *pwidth, startmask);
  286.         *addrl ^= startmask;
  287.         }
  288.         else
  289.         {
  290.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  291.         if (startmask)
  292.             *addrl++ ^= startmask;
  293.         Duff (nlmiddle, *addrl++ ^= 0xffffffff);
  294.         if (endmask)
  295.             *addrl ^= endmask;
  296.         }
  297.     }
  298.     pwidth++;
  299.     ppt++;
  300.     }
  301.     DEALLOCATE_LOCAL(pptFree);
  302.     DEALLOCATE_LOCAL(pwidthFree);
  303. }
  304.  
  305.  
  306. void 
  307. mfbWhiteStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  308. DrawablePtr pDrawable;
  309. GC *pGC;
  310. int nInit;            /* number of spans to fill */
  311. DDXPointPtr pptInit;        /* pointer to list of start points */
  312. int *pwidthInit;        /* pointer to list of n widths */
  313. int fSorted;
  314. {
  315.                 /* next three parameters are post-clip */
  316.     int n;            /* number of spans to fill */
  317.     register DDXPointPtr ppt;    /* pointer to list of start points */
  318.     register int *pwidth;    /* pointer to list of n widths */
  319.     int *addrlBase;        /* pointer to start of bitmap */
  320.     int nlwidth;        /* width in longwords of bitmap */
  321.     register int *addrl;    /* pointer to current longword in bitmap */
  322.     register int src;
  323.     register int nlmiddle;
  324.     register int startmask;
  325.     register int endmask;
  326.     PixmapPtr pStipple;
  327.     int *psrc;
  328.     int tileHeight;
  329.     int *pwidthFree;        /* copies of the pointers to free */
  330.     DDXPointPtr pptFree;
  331.  
  332.     if (!(pGC->planemask & 1))
  333.     return;
  334.  
  335.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  336.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  337.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  338.     if(!pptFree || !pwidthFree)
  339.     {
  340.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  341.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  342.     return;
  343.     }
  344.     pwidth = pwidthFree;
  345.     ppt = pptFree;
  346.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  347.             pptInit, pwidthInit, nInit, 
  348.             ppt, pwidth, fSorted);
  349.  
  350.     if (pDrawable->type == DRAWABLE_WINDOW)
  351.     {
  352.     addrlBase = (int *)
  353.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  354.     nlwidth = (int)
  355.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  356.     }
  357.     else
  358.     {
  359.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  360.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  361.     }
  362.  
  363.     pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
  364.     tileHeight = pStipple->drawable.height;
  365.     psrc = (int *)(pStipple->devPrivate.ptr);
  366.  
  367.     while (n--)
  368.     {
  369.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  370.     src = psrc[ppt->y % tileHeight];
  371.  
  372.         /* all bits inside same longword */
  373.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  374.         {
  375.         maskpartialbits(ppt->x, *pwidth, startmask);
  376.         *addrl |= (src & startmask);
  377.         }
  378.         else
  379.         {
  380.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  381.         if (startmask)
  382.         *addrl++ |= (src & startmask);
  383.         Duff (nlmiddle, *addrl++ |= src);
  384.         if (endmask)
  385.         *addrl |= (src & endmask);
  386.         }
  387.     pwidth++;
  388.     ppt++;
  389.     }
  390.     DEALLOCATE_LOCAL(pptFree);
  391.     DEALLOCATE_LOCAL(pwidthFree);
  392. }
  393.  
  394.  
  395. void 
  396. mfbBlackStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  397. DrawablePtr pDrawable;
  398. GC *pGC;
  399. int nInit;            /* number of spans to fill */
  400. DDXPointPtr pptInit;        /* pointer to list of start points */
  401. int *pwidthInit;        /* pointer to list of n widths */
  402. int fSorted;
  403. {
  404.                 /* next three parameters are post-clip */
  405.     int n;            /* number of spans to fill */
  406.     register DDXPointPtr ppt;    /* pointer to list of start points */
  407.     register int *pwidth;    /* pointer to list of n widths */
  408.     int *addrlBase;        /* pointer to start of bitmap */
  409.     int nlwidth;        /* width in longwords of bitmap */
  410.     register int *addrl;    /* pointer to current longword in bitmap */
  411.     register int src;
  412.     register int nlmiddle;
  413.     register int startmask;
  414.     register int endmask;
  415.     PixmapPtr pStipple;
  416.     int *psrc;
  417.     int tileHeight;
  418.     int *pwidthFree;        /* copies of the pointers to free */
  419.     DDXPointPtr pptFree;
  420.  
  421.     if (!(pGC->planemask & 1))
  422.     return;
  423.  
  424.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  425.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  426.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  427.     if(!pptFree || !pwidthFree)
  428.     {
  429.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  430.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  431.     return;
  432.     }
  433.     pwidth = pwidthFree;
  434.     ppt = pptFree;
  435.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  436.             pptInit, pwidthInit, nInit, 
  437.             ppt, pwidth, fSorted);
  438.  
  439.     if (pDrawable->type == DRAWABLE_WINDOW)
  440.     {
  441.     addrlBase = (int *)
  442.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  443.     nlwidth = (int)
  444.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  445.     }
  446.     else
  447.     {
  448.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  449.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  450.     }
  451.  
  452.     pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
  453.     tileHeight = pStipple->drawable.height;
  454.     psrc = (int *)(pStipple->devPrivate.ptr);
  455.  
  456.     while (n--)
  457.     {
  458.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  459.     src = psrc[ppt->y % tileHeight];
  460.  
  461.         /* all bits inside same longword */
  462.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  463.         {
  464.         maskpartialbits(ppt->x, *pwidth, startmask);
  465.         *addrl &= ~(src & startmask);
  466.         }
  467.         else
  468.         {
  469.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  470.         if (startmask)
  471.         *addrl++ &= ~(src & startmask);
  472.         Duff (nlmiddle, *addrl++ &= ~src);
  473.         if (endmask)
  474.         *addrl &= ~(src & endmask);
  475.         }
  476.     pwidth++;
  477.     ppt++;
  478.     }
  479.     DEALLOCATE_LOCAL(pptFree);
  480.     DEALLOCATE_LOCAL(pwidthFree);
  481. }
  482.  
  483.  
  484. void 
  485. mfbInvertStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  486. DrawablePtr pDrawable;
  487. GC *pGC;
  488. int nInit;            /* number of spans to fill */
  489. DDXPointPtr pptInit;        /* pointer to list of start points */
  490. int *pwidthInit;        /* pointer to list of n widths */
  491. int fSorted;
  492. {
  493.                 /* next three parameters are post-clip */
  494.     int n;            /* number of spans to fill */
  495.     register DDXPointPtr ppt;    /* pointer to list of start points */
  496.     register int *pwidth;    /* pointer to list of n widths */
  497.     int *addrlBase;        /* pointer to start of bitmap */
  498.     int nlwidth;        /* width in longwords of bitmap */
  499.     register int *addrl;    /* pointer to current longword in bitmap */
  500.     register int src;
  501.     register int nlmiddle;
  502.     register int startmask;
  503.     register int endmask;
  504.     PixmapPtr pStipple;
  505.     int *psrc;
  506.     int tileHeight;
  507.     int *pwidthFree;        /* copies of the pointers to free */
  508.     DDXPointPtr pptFree;
  509.  
  510.     if (!(pGC->planemask & 1))
  511.     return;
  512.  
  513.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  514.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  515.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  516.     if(!pptFree || !pwidthFree)
  517.     {
  518.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  519.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  520.     return;
  521.     }
  522.     pwidth = pwidthFree;
  523.     ppt = pptFree;
  524.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  525.             pptInit, pwidthInit, nInit, 
  526.             ppt, pwidth, fSorted);
  527.  
  528.     if (pDrawable->type == DRAWABLE_WINDOW)
  529.     {
  530.     addrlBase = (int *)
  531.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  532.     nlwidth = (int)
  533.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  534.     }
  535.     else
  536.     {
  537.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  538.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  539.     }
  540.  
  541.     pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
  542.     tileHeight = pStipple->drawable.height;
  543.     psrc = (int *)(pStipple->devPrivate.ptr);
  544.  
  545.     while (n--)
  546.     {
  547.         addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  548.     src = psrc[ppt->y % tileHeight];
  549.  
  550.         /* all bits inside same longword */
  551.         if ( ((ppt->x & 0x1f) + *pwidth) < 32)
  552.         {
  553.         maskpartialbits(ppt->x, *pwidth, startmask);
  554.         *addrl ^= (src & startmask);
  555.         }
  556.         else
  557.         {
  558.         maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
  559.         if (startmask)
  560.         *addrl++ ^= (src & startmask);
  561.         Duff(nlmiddle, *addrl++ ^= src);
  562.         if (endmask)
  563.         *addrl ^= (src & endmask);
  564.         }
  565.     pwidth++;
  566.     ppt++;
  567.     }
  568.     DEALLOCATE_LOCAL(pptFree);
  569.     DEALLOCATE_LOCAL(pwidthFree);
  570. }
  571.  
  572.  
  573. /* this works with tiles of width == 32 */
  574. #define FILLSPAN32(ROP) \
  575.     while (n--) \
  576.     { \
  577.     if (*pwidth) \
  578.     { \
  579.             addrl = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5); \
  580.         src = psrc[ppt->y % tileHeight]; \
  581.             if ( ((ppt->x & 0x1f) + *pwidth) < 32) \
  582.             { \
  583.             maskpartialbits(ppt->x, *pwidth, startmask); \
  584.             *addrl = (*addrl & ~startmask) | \
  585.                  (ROP(src, *addrl) & startmask); \
  586.             } \
  587.             else \
  588.             { \
  589.             maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle); \
  590.             if (startmask) \
  591.             { \
  592.                 *addrl = (*addrl & ~startmask) | \
  593.                  (ROP(src, *addrl) & startmask); \
  594.             addrl++; \
  595.             } \
  596.             while (nlmiddle--) \
  597.             { \
  598.             *addrl = ROP(src, *addrl); \
  599.             addrl++; \
  600.             } \
  601.             if (endmask) \
  602.                 *addrl = (*addrl & ~endmask) | \
  603.                  (ROP(src, *addrl) & endmask); \
  604.             } \
  605.     } \
  606.     pwidth++; \
  607.     ppt++; \
  608.     }
  609.  
  610.  
  611.  
  612. void mfbTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  613. DrawablePtr pDrawable;
  614. GC *pGC;
  615. int nInit;            /* number of spans to fill */
  616. DDXPointPtr pptInit;        /* pointer to list of start points */
  617. int *pwidthInit;        /* pointer to list of n widths */
  618. int fSorted;
  619. {
  620.                 /* next three parameters are post-clip */
  621.     int n;            /* number of spans to fill */
  622.     register DDXPointPtr ppt;    /* pointer to list of start points */
  623.     register int *pwidth;    /* pointer to list of n widths */
  624.     int *addrlBase;        /* pointer to start of bitmap */
  625.     int nlwidth;        /* width in longwords of bitmap */
  626.     register int *addrl;    /* pointer to current longword in bitmap */
  627.     register int src;
  628.     register int nlmiddle;
  629.     register int startmask;
  630.     register int endmask;
  631.     PixmapPtr pTile;
  632.     int *psrc;
  633.     int tileHeight;
  634.     int rop;
  635.     int *pwidthFree;        /* copies of the pointers to free */
  636.     DDXPointPtr pptFree;
  637.  
  638.     if (!(pGC->planemask & 1))
  639.     return;
  640.  
  641.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  642.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  643.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  644.     if(!pptFree || !pwidthFree)
  645.     {
  646.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  647.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  648.     return;
  649.     }
  650.     pwidth = pwidthFree;
  651.     ppt = pptFree;
  652.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  653.             pptInit, pwidthInit, nInit, 
  654.             ppt, pwidth, fSorted);
  655.  
  656.     if (pDrawable->type == DRAWABLE_WINDOW)
  657.     {
  658.     addrlBase = (int *)
  659.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  660.     nlwidth = (int)
  661.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  662.     }
  663.     else
  664.     {
  665.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  666.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  667.     }
  668.  
  669.     pTile = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
  670.     tileHeight = pTile->drawable.height;
  671.     psrc = (int *)(pTile->devPrivate.ptr);
  672.     if (pGC->fillStyle == FillTiled)
  673.     rop = pGC->alu;
  674.     else
  675.     rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
  676.  
  677.     switch(rop)
  678.     {
  679.       case GXclear:
  680.     FILLSPAN32(fnCLEAR)
  681.     break;
  682.       case GXand:
  683.     FILLSPAN32(fnAND)
  684.     break;
  685.       case GXandReverse:
  686.     FILLSPAN32(fnANDREVERSE)
  687.     break;
  688.       case GXcopy:
  689.     FILLSPAN32(fnCOPY)
  690.     break;
  691.       case GXandInverted:
  692.     FILLSPAN32(fnANDINVERTED)
  693.     break;
  694.       case GXnoop:
  695.     break;
  696.       case GXxor:
  697.     FILLSPAN32(fnXOR)
  698.     break;
  699.       case GXor:
  700.     FILLSPAN32(fnOR)
  701.     break;
  702.       case GXnor:
  703.     FILLSPAN32(fnNOR)
  704.     break;
  705.       case GXequiv:
  706.     FILLSPAN32(fnEQUIV)
  707.     break;
  708.       case GXinvert:
  709.     FILLSPAN32(fnINVERT)
  710.     break;
  711.       case GXorReverse:
  712.     FILLSPAN32(fnORREVERSE)
  713.     break;
  714.       case GXcopyInverted:
  715.     FILLSPAN32(fnCOPYINVERTED)
  716.     break;
  717.       case GXorInverted:
  718.     FILLSPAN32(fnORINVERTED)
  719.     break;
  720.       case GXnand:
  721.     FILLSPAN32(fnNAND)
  722.     break;
  723.       case GXset:
  724.     FILLSPAN32(fnSET)
  725.     break;
  726.     }
  727.     DEALLOCATE_LOCAL(pptFree);
  728.     DEALLOCATE_LOCAL(pwidthFree);
  729. }
  730.  
  731.  
  732. /* Fill spans with tiles that aren't 32 bits wide */
  733. void
  734. mfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  735. DrawablePtr pDrawable;
  736. GC        *pGC;
  737. int        nInit;        /* number of spans to fill */
  738. DDXPointPtr pptInit;        /* pointer to list of start points */
  739. int *pwidthInit;        /* pointer to list of n widths */
  740. int fSorted;
  741. {
  742.     int        iline;        /* first line of tile to use */
  743.                 /* next three parameters are post-clip */
  744.     int n;            /* number of spans to fill */
  745.     register DDXPointPtr ppt;    /* pointer to list of start points */
  746.     register int *pwidth;    /* pointer to list of n widths */
  747.     unsigned int *addrlBase;    /* pointer to start of bitmap */
  748.     int         nlwidth;    /* width in longwords of bitmap */
  749.     register unsigned int *pdst;/* pointer to current word in bitmap */
  750.     register unsigned int *psrc;/* pointer to current word in tile */
  751.     register int nlMiddle;
  752.     register int rop, nstart;
  753.     unsigned int startmask;
  754.     PixmapPtr    pTile;        /* pointer to tile we want to fill with */
  755.     int        w, width, x, xSrc, ySrc, srcStartOver, nend;
  756.     int     tlwidth, rem, tileWidth, tileHeight, endinc;
  757.     unsigned int      endmask, *psrcT;
  758.     int *pwidthFree;        /* copies of the pointers to free */
  759.     DDXPointPtr pptFree;
  760.  
  761.     if (!(pGC->planemask & 1))
  762.     return;
  763.  
  764.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  765.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  766.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  767.     if(!pptFree || !pwidthFree)
  768.     {
  769.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  770.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  771.     return;
  772.     }
  773.     pwidth = pwidthFree;
  774.     ppt = pptFree;
  775.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  776.             pptInit, pwidthInit, nInit, 
  777.             ppt, pwidth, fSorted);
  778.  
  779.     if (pGC->fillStyle == FillTiled)
  780.     {
  781.     pTile = pGC->tile.pixmap;
  782.     tlwidth = pTile->devKind >> 2;
  783.     rop = pGC->alu;
  784.     }
  785.     else
  786.     {
  787.     pTile = pGC->stipple;
  788.     tlwidth = pTile->devKind >> 2;
  789.     rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
  790.     }
  791.  
  792.     xSrc = pDrawable->x;
  793.     ySrc = pDrawable->y;
  794.  
  795.     if (pDrawable->type == DRAWABLE_WINDOW)
  796.     {
  797.     addrlBase = (unsigned int *)
  798.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  799.     nlwidth = (int)
  800.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  801.     }
  802.     else
  803.     {
  804.     addrlBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  805.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  806.     }
  807.  
  808.     tileWidth = pTile->drawable.width;
  809.     tileHeight = pTile->drawable.height;
  810.  
  811.     /* this replaces rotating the tile. Instead we just adjust the offset
  812.      * at which we start grabbing bits from the tile.
  813.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  814.      * so that iline and rem always stay within the tile bounds.
  815.      */
  816.     xSrc += (pGC->patOrg.x % tileWidth) - tileWidth;
  817.     ySrc += (pGC->patOrg.y % tileHeight) - tileHeight;
  818.  
  819.     while (n--)
  820.     {
  821.     iline = (ppt->y - ySrc) % tileHeight;
  822.         pdst = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  823.         psrcT = (unsigned int *) pTile->devPrivate.ptr + (iline * tlwidth);
  824.     x = ppt->x;
  825.  
  826.     if (*pwidth)
  827.     {
  828.         width = *pwidth;
  829.         while(width > 0)
  830.         {
  831.         psrc = psrcT;
  832.             w = min(tileWidth, width);
  833.         if((rem = (x - xSrc)  % tileWidth) != 0)
  834.         {
  835.             /* if we're in the middle of the tile, get
  836.                as many bits as will finish the span, or
  837.                as many as will get to the left edge of the tile,
  838.                or a longword worth, starting at the appropriate
  839.                offset in the tile.
  840.             */
  841.             w = min(min(tileWidth - rem, width), BITMAP_SCANLINE_UNIT);
  842.             endinc = rem / BITMAP_SCANLINE_UNIT;
  843.             getandputrop((psrc+endinc), (rem&0x1f), (x & 0x1f), w, pdst, rop);
  844.             if((x & 0x1f) + w >= 0x20)
  845.             pdst++;
  846.         }
  847.         else if(((x & 0x1f) + w) < 32)
  848.         {
  849.             /* doing < 32 bits is easy, and worth special-casing */
  850.             putbitsrop(*psrc, x & 0x1f, w, pdst, rop);
  851.         }
  852.         else
  853.         {
  854.             /* start at the left edge of the tile,
  855.                and put down as much as we can
  856.             */
  857.             maskbits(x, w, startmask, endmask, nlMiddle);
  858.  
  859.                 if (startmask)
  860.                 nstart = 32 - (x & 0x1f);
  861.                 else
  862.                 nstart = 0;
  863.                 if (endmask)
  864.                     nend = (x + w)  & 0x1f;
  865.                 else
  866.                 nend = 0;
  867.  
  868.                 srcStartOver = nstart > 31;
  869.  
  870.             if(startmask)
  871.             {
  872.             putbitsrop(*psrc, (x & 0x1f), nstart, pdst, rop);
  873.             pdst++;
  874.             if(srcStartOver)
  875.                 psrc++;
  876.             }
  877.              
  878.             while(nlMiddle--)
  879.             {
  880.                 getandputrop0(psrc, nstart, 32, pdst, rop);
  881.                 pdst++;
  882.                 psrc++;
  883.             }
  884.             if(endmask)
  885.             {
  886.             getandputrop0(psrc, nstart, nend, pdst, rop);
  887.             }
  888.          }
  889.          x += w;
  890.          width -= w;
  891.         }
  892.     }
  893.     ppt++;
  894.     pwidth++;
  895.     }
  896.     DEALLOCATE_LOCAL(pptFree);
  897.     DEALLOCATE_LOCAL(pwidthFree);
  898. }
  899.  
  900.  
  901. /* Fill spans with stipples that aren't 32 bits wide */
  902. void
  903. mfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  904. DrawablePtr pDrawable;
  905. GC        *pGC;
  906. int        nInit;        /* number of spans to fill */
  907. DDXPointPtr pptInit;        /* pointer to list of start points */
  908. int *pwidthInit;        /* pointer to list of n widths */
  909. int fSorted;
  910. {
  911.                 /* next three parameters are post-clip */
  912.     int n;            /* number of spans to fill */
  913.     register DDXPointPtr ppt;    /* pointer to list of start points */
  914.     register int *pwidth;    /* pointer to list of n widths */
  915.     int        iline;        /* first line of tile to use */
  916.     int        *addrlBase;    /* pointer to start of bitmap */
  917.     int         nlwidth;    /* width in longwords of bitmap */
  918.     register int *pdst;        /* pointer to current word in bitmap */
  919.     register int *psrc;        /* pointer to current word in tile */
  920.     register int nlMiddle;
  921.     register int rop, nstart;
  922.     int startmask;
  923.     PixmapPtr    pTile;        /* pointer to tile we want to fill with */
  924.     int        w, width,  x, xSrc, ySrc, srcStartOver, nend;
  925.     int     endmask, tlwidth, rem, tileWidth, *psrcT, endinc;
  926.     int        tileHeight;
  927.     int *pwidthFree;        /* copies of the pointers to free */
  928.     DDXPointPtr pptFree;
  929.  
  930.     if (!(pGC->planemask & 1))
  931.     return;
  932.  
  933.     n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  934.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  935.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  936.     if(!pptFree || !pwidthFree)
  937.     {
  938.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  939.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  940.     return;
  941.     }
  942.     pwidth = pwidthFree;
  943.     ppt = pptFree;
  944.     n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
  945.             pptInit, pwidthInit, nInit, 
  946.             ppt, pwidth, fSorted);
  947.  
  948.     pTile = pGC->stipple;
  949.     rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
  950.     tlwidth = pTile->devKind >> 2;
  951.     xSrc = pDrawable->x;
  952.     ySrc = pDrawable->y;
  953.     if (pDrawable->type == DRAWABLE_WINDOW)
  954.     {
  955.     addrlBase = (int *)
  956.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  957.     nlwidth = (int)
  958.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  959.     }
  960.     else
  961.     {
  962.     addrlBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  963.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  964.     }
  965.  
  966.     tileWidth = pTile->drawable.width;
  967.     tileHeight = pTile->drawable.height;
  968.  
  969.     /* this replaces rotating the stipple.  Instead, we just adjust the offset
  970.      * at which we start grabbing bits from the stipple.
  971.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  972.      * so that iline and rem always stay within the tile bounds.
  973.      */
  974.     xSrc += (pGC->patOrg.x % tileWidth) - tileWidth;
  975.     ySrc += (pGC->patOrg.y % tileHeight) - tileHeight;
  976.     while (n--)
  977.     {
  978.     iline = (ppt->y - ySrc) % tileHeight;
  979.         pdst = addrlBase + (ppt->y * nlwidth) + (ppt->x >> 5);
  980.         psrcT = (int *) pTile->devPrivate.ptr + (iline * tlwidth);
  981.     x = ppt->x;
  982.  
  983.     if (*pwidth)
  984.     {
  985.         width = *pwidth;
  986.         while(width > 0)
  987.         {
  988.         psrc = psrcT;
  989.             w = min(tileWidth, width);
  990.         if((rem = (x - xSrc) % tileWidth) != 0)
  991.         {
  992.             /* if we're in the middle of the tile, get
  993.                as many bits as will finish the span, or
  994.                as many as will get to the left edge of the tile,
  995.                or a longword worth, starting at the appropriate
  996.                offset in the tile.
  997.             */
  998.             w = min(min(tileWidth - rem, width), BITMAP_SCANLINE_UNIT);
  999.             endinc = rem / BITMAP_SCANLINE_UNIT;
  1000.             getandputrrop((psrc + endinc), (rem & 0x1f), (x & 0x1f),
  1001.                  w, pdst, rop)
  1002.             if((x & 0x1f) + w >= 0x20)
  1003.             pdst++;
  1004.         }
  1005.  
  1006.         else if(((x & 0x1f) + w) < 32)
  1007.         {
  1008.             /* doing < 32 bits is easy, and worth special-casing */
  1009.             putbitsrrop(*psrc, x & 0x1f, w, pdst, rop);
  1010.         }
  1011.         else
  1012.         {
  1013.             /* start at the left edge of the tile,
  1014.                and put down as much as we can
  1015.             */
  1016.             maskbits(x, w, startmask, endmask, nlMiddle);
  1017.  
  1018.                 if (startmask)
  1019.                 nstart = 32 - (x & 0x1f);
  1020.                 else
  1021.                 nstart = 0;
  1022.                 if (endmask)
  1023.                     nend = (x + w)  & 0x1f;
  1024.                 else
  1025.                 nend = 0;
  1026.  
  1027.                 srcStartOver = nstart > 31;
  1028.  
  1029.             if(startmask)
  1030.             {
  1031.             putbitsrrop(*psrc, (x & 0x1f), nstart, pdst, rop);
  1032.             pdst++;
  1033.             if(srcStartOver)
  1034.                 psrc++;
  1035.             }
  1036.              
  1037.             while(nlMiddle--)
  1038.             {
  1039.                 getandputrrop0(psrc, nstart, 32, pdst, rop);
  1040.                 pdst++;
  1041.                 psrc++;
  1042.             }
  1043.             if(endmask)
  1044.             {
  1045.             getandputrrop0(psrc, nstart, nend, pdst, rop);
  1046.             }
  1047.          }
  1048.          x += w;
  1049.          width -= w;
  1050.         }
  1051.     }
  1052.     ppt++;
  1053.     pwidth++;
  1054.     }
  1055.     DEALLOCATE_LOCAL(pptFree);
  1056.     DEALLOCATE_LOCAL(pwidthFree);
  1057. }
  1058.